<template>
  <div class="articleItem">
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ articleItem.title }}</span>
          <!-- 单图 -->
          <img
            class="thumb"
            v-lazy="pathFilter(articleItem.cover.images[0])"
            v-if="articleItem.cover.type === 1"
          />
        </div>
        <!-- 三张图片 -->
        <div class="thumb-box" v-if="articleItem.cover.type > 1">
          <img
            class="thumb"
            v-lazy="pathFilter(imgUrl)"
            v-for="(imgUrl, index) in articleItem.cover.images"
            :key="index"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ articleItem.aut_name }}</span>
            <span>{{ articleItem.comm_count }} 评论</span>
            <span>{{ articleItem.pubdate }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="onCloseClick" v-if="isShow"/>
        </div>
      </template>
    </van-cell>
    <!-- 反馈面板 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      :cancel-text="cancelText"
      description="反馈和建议"
      @select="onSelect"
      get-container="body"
      @cancel="onCancel"
      @close="onclose"
    />
  </div>
</template>

<script>
const firstActions = [{ name: "不感兴趣" }, { name: "反馈垃圾内容" }];
const secondActions = [
  {
    value: 0,
    name: "其它问题",
  },
  {
    value: 1,
    name: "标题夸张",
  },
  {
    value: 2,
    name: "低俗色情",
  },
  {
    value: 3,
    name: "错别字多",
  },
  {
    value: 4,
    name: "旧闻重复",
  },
  {
    value: 6,
    name: "内容不实",
  },
  {
    value: 8,
    name: "侵权",
  },
  {
    value: 5,
    name: "广告软文",
  },
  {
    value: 7,
    name: "涉嫌违法犯罪",
  },
];
export default {
  props: {
    articleItem: {
      type: Object,
      default() {
        return {};
      },
    },
    isShow:{
      type:Boolean,
      default: true
    }
  },
  data() {
    return {
      show: false,
      actions: firstActions,
      cancelText: '取消'
    };
  },
  methods: {
    // 图片url过滤器
    pathFilter(url) {
      return "http://chenziyu.xyz:8000/" + url.split("8000/")[1];
    },
    // 点击了叉号按钮
    onCloseClick() {
      // 展示动作面板
      this.show = true;
    },
    // 反馈面板点击事件
    onSelect(action) {
      if(action.name === '反馈垃圾内容'){
        this.actions = secondActions;
        this.cancelText = '返回';

      }else if(action.name === '不感兴趣'){
        this.$emit('dislike', this.articleItem);
        this.show = false;
      }else {
        this.$emit('reports', this.articleItem, action.value);
        this.show = false;
      }
    },
    // 取消事件
    onCancel(){
      if(this.cancelText === '返回'){
        this.show = true;
        this.actions = firstActions;
        this.cancelText = '取消';
      }
    },
    // 面板关闭事件
    onclose(){
      this.actions = firstActions;
    }
  },
};
</script>

<style lang="less" scoped>
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
